// ******************************************************************
// * Copyright(c)  Steven Lu
// * Description   : Entity_HR_ATTENDANCE_CARD_LOSS
// * CreateDate    : 2013-08-28 11:00:56
// * Creater       : CodeSmith
// * LastChangeDate: 2013-08-28 11:00:56
// * LastChanger   : 2013-08-28 11:00:56
// * Version Info  : 1.0 For ESOL
// ******************************************************************

using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Suzsoft.Smart.Data;
using ESOL.Common.Entity;

namespace ESOL.Business.Hr
{
/// <summary>
    /// HrAttendanceCardLoss
    /// </summary>
    public partial class HrAttendanceCardLossBs
    {
        #region GetByID
        /// <summary>
        /// Get Entity
        /// </summary>
        /// <param name="objHrAttendanceCardLossEntity">Entity</param>
        /// <returns>Entity</returns>
        public static HrAttendanceCardLossEntity GetHrAttendanceCardLoss(HrAttendanceCardLossEntity objHrAttendanceCardLossEntity)
        {
            return DataAccess.SelectSingle<HrAttendanceCardLossEntity>(objHrAttendanceCardLossEntity);
        }
        #endregion


        #region Insert
        /// <summary>
        /// Insert Data
        /// </summary>
        /// <param name="objHrAttendanceCardLossEntity">Entity</param>
        /// <returns>true Insert Succeed; false Insert Fail</returns>
        public static bool InsertHrAttendanceCardLoss(HrAttendanceCardLossEntity objHrAttendanceCardLossEntity)
        {
            return DataAccess.Insert(objHrAttendanceCardLossEntity);
        }

        public static bool InsertHrAttendanceCardLoss(List<HrAttendanceCardLossEntity> objHrAttendanceCardLossEntityList)
        {
            return DataAccess.Insert(objHrAttendanceCardLossEntityList);
        }
        #endregion


        #region Update
        /// <summary>
        /// Update Data
        /// </summary>
        /// <param name="objHrAttendanceCardLossEntity">Entity</param>
        /// <returns>true Update Succeed; false Update Fail</returns>
        public static bool UpdateHrAttendanceCardLoss(HrAttendanceCardLossEntity objHrAttendanceCardLossEntity)
        {
            return DataAccess.Update(objHrAttendanceCardLossEntity);
        }

        public static bool UpdateHrAttendanceCardLoss(List<HrAttendanceCardLossEntity> objHrAttendanceCardLossEntityList)
        {
            return DataAccess.Update<HrAttendanceCardLossEntity>(objHrAttendanceCardLossEntityList);
        }
        #endregion


        #region Delete
        /// <summary>
        /// Delete Data
        /// </summary>
        /// <param name="objHrAttendanceCardLossEntity">Entity</param>
        /// <returns>true Delete Succeed; false Delete Fail</returns>
        public static bool DeleteHrAttendanceCardLoss(HrAttendanceCardLossEntity objHrAttendanceCardLossEntity)
        {
            return DataAccess.Delete(objHrAttendanceCardLossEntity);
        }

        public static bool DeleteHrAttendanceCardLoss(List<HrAttendanceCardLossEntity> objHrAttendanceCardLossEntityList)
        {
            return DataAccess.Delete<HrAttendanceCardLossEntity>(objHrAttendanceCardLossEntityList);
        }
        #endregion


        #region GetAll
        /// <summary>
        /// Get All Data
        /// </summary>
        /// <returns>Back All Data<returns>
        public static DataSet GetHrAttendanceCardLossAll()
        {
            return DataAccess.SelectAllDataSet<HrAttendanceCardLossEntity>();
        }
        /// <summary>
        /// Get All Data List
        /// </summary>
        /// <returns>Back All Data List<returns>
        public static List<HrAttendanceCardLossEntity> GetHrAttendanceCardLossAllList()
        {
            return DataAccess.SelectAll<HrAttendanceCardLossEntity>();
        }
        #endregion

        public static DataTable GetCardLossByCondition(DTOHrAttendanceCardLossEntity condition)
        {
            string sql = @"Select {0} ACL.*, P.EMPLOYEE_NAME , P.DEPARTMENT_NO,P.POSITION_ID
                                FROM  HR_ATTENDANCE_CARD_LOSS ACL
                                LEFT JOIN hr_employee P ON P.Employee_NO = ACL.PERSON_ID
                                WHERE 1=1 ";

            if (condition != null && condition.result!=null)
            {
                sql = string.Format(sql, condition.rowCount > 0 ? " top " + condition.rowCount : "");
                HrAttendanceCardLossEntity c= condition.result;

                if(!string.IsNullOrEmpty(c.LossId))
                    sql += " AND ACL.LOSS_ID = '" + c.LossId + "'";

                if (!string.IsNullOrEmpty(c.DepartmentId))
                    sql += " AND ACL.DEPARTMENT_ID = '" + c.DepartmentId + "'";
                if (!string.IsNullOrEmpty(c.PersonId))
                    sql += " AND ACL.PERSON_ID = '" + c.PersonId + "'";

                if (!string.IsNullOrEmpty(c.Status))
                    sql += " AND ACL.STATUS = '" + c.Status + "'";

                if (c.CardLossDate > DateTime.MinValue)
                {
                    sql += " AND ACL.CARD_LOSS_DATE >= CONVERT(DATETIME,'" + c.CardLossDate.ToString("yyyy-MM-dd") + " 00:00:00')";
                }

            }

            sql += " ORDER BY CARD_LOSS_DATE DESC";

            DataSet ds = DataAccess.SelectDataSet(sql);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            return null;

        }

        
    }
	
}	

